#include "ksvgloadtask.h"

#include <QGraphicsScene>
#include <QFileInfo>
#include <QDebug>
#include "kexportshape.h"
#include "ksvgfilemanager.h"

KSvgLoadTask::KSvgLoadTask(const QString& filePath,
                           const QList<KExportShape*>& shapeList,
                           const QRectF& sceneRect,
                           const QColor& canvasColor)
    : m_filePath(filePath),
    m_shapeList(shapeList),
    m_sceneRect(sceneRect),
    m_canvasColor(canvasColor)
{
    setAutoDelete(true);
}

void KSvgLoadTask::run()
{
    QList<KExportShape*> shapeList;
    QRectF sceneRect;
    QColor canvasColor;
    bool ok = KSvgFileManager::loadSvgFile(m_filePath, shapeList, sceneRect, canvasColor);
    if (!ok) {
        qWarning() << "[KSvgLoadTask] Failed to load SVG:" << m_filePath;
        return;
    }
    QString tabName = QFileInfo(m_filePath).fileName();
    emit loadFinished(shapeList, sceneRect, canvasColor, tabName);
}